package com.ruoyi.supervise.service.impl.decisupport;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.supervise.config.CityConfig;
import com.ruoyi.supervise.domain.decisupport.City;
import com.ruoyi.supervise.domain.decisupport.ComparisonMap;
import com.ruoyi.supervise.domain.decisupport.ConstructionProject;
import com.ruoyi.supervise.mapper.decisupport.ComparisonMapMapper;
import com.ruoyi.supervise.service.decisupport.ComparisonMapService;

@Service
@DataSource(value = DataSourceType.SLAVE)
public class ComparisonMapServiceImpl implements ComparisonMapService{

    @Autowired
    private ComparisonMapMapper comparisonMapMapper;
    
    @Autowired
    private CityConfig cityConfig;

	@Override
	public List<ComparisonMap> selectAllStartProNumNowAndLast(ConstructionProject cp) {
		// TODO Auto-generated method stub
		return comparisonMapMapper.selectAllStartProNumNowAndLast(cp);
	}

	@Override
	public List<ComparisonMap> selectAllStartProNumNowAndLastDBT(ConstructionProject cp) {
		List<ComparisonMap> cmList=comparisonMapMapper.selectAllStartProNumNowAndLast(cp);
		String numNow=comparisonMapMapper.countAllStartProNumNow(cp);
		String numLast=comparisonMapMapper.countAllStartProNumLast(cp);
		ComparisonMap myCM=new ComparisonMap();
		myCM.setProjectCityNum("全省");
		myCM.setNow(numNow);
		myCM.setLast(numLast);
		List<ComparisonMap> comparisonMapList=new ArrayList<ComparisonMap>();
		comparisonMapList.add(0, myCM);
		for(City c:cityConfig.getCityList())
		{
			ComparisonMap cm=new ComparisonMap();
			cm.setProjectCityNum(c.getCityname());
			cm.setNow("0");
			cm.setLast("0");
			comparisonMapList.add(cm);
		}
		for(ComparisonMap cml:comparisonMapList)
		{
			for(ComparisonMap cm:cmList)
			{
				if(cml.getProjectCityNum().equals(cm.getProjectCityNum()))
				{
					BigDecimal now = new BigDecimal(cm.getNow());
					BigDecimal last = new BigDecimal(cm.getLast());
					cml.setNow(now.toPlainString());
					cml.setLast(last.toPlainString());
				}
			}
		}
		return comparisonMapList;
	}

	@Override
	public List<ComparisonMap> selectAllStartProMoneyNowAndLast(ConstructionProject cp) {
		// TODO Auto-generated method stub
		return comparisonMapMapper.selectAllStartProMoneyNowAndLast(cp);
	}

	@Override
	public List<ComparisonMap> selectAllStartProMoneyNowAndLastDBT(ConstructionProject cp) {
		List<ComparisonMap> moneyList=comparisonMapMapper.selectAllStartProMoneyNowAndLast(cp);
		String moneyNow=comparisonMapMapper.countAllStartProMoneyNow(cp);
		String moneyLast=comparisonMapMapper.countAllStartProMoneyLast(cp);
		ComparisonMap myCM=new ComparisonMap();
		myCM.setProjectCityNum("全省");
		myCM.setNow(moneyNow);
		myCM.setLast(moneyLast);
		List<ComparisonMap> comparisonMapList=new ArrayList<ComparisonMap>();
		comparisonMapList.add(0, myCM);
		for(City c:cityConfig.getCityList())
		{
			ComparisonMap cm=new ComparisonMap();
			cm.setProjectCityNum(c.getCityname());
			cm.setNow("0");
			cm.setLast("0");
			comparisonMapList.add(cm);
		}
		for(ComparisonMap cml:comparisonMapList)
		{
			for(ComparisonMap cm:moneyList)
			{
				if(cml.getProjectCityNum().equals(cm.getProjectCityNum()))
				{
					BigDecimal now = new BigDecimal(cm.getNow());
					BigDecimal last = new BigDecimal(cm.getLast());
					cml.setNow(now.toPlainString());
					cml.setLast(last.toPlainString());
				}
			}
		}
		return comparisonMapList;
	}

	@Override
	public String countAllStartProNumNow(ConstructionProject cp) {
		// TODO Auto-generated method stub
		return comparisonMapMapper.countAllStartProNumNow(cp);
	}

	@Override
	public String countAllStartProNumLast(ConstructionProject cp) {
		// TODO Auto-generated method stub
		return comparisonMapMapper.countAllStartProNumLast(cp);
	}

	@Override
	public String countAllStartProMoneyNow(ConstructionProject cp) {
		// TODO Auto-generated method stub
		return comparisonMapMapper.countAllStartProMoneyNow(cp);
	}

	@Override
	public String countAllStartProMoneyLast(ConstructionProject cp) {
		// TODO Auto-generated method stub
		return comparisonMapMapper.countAllStartProMoneyLast(cp);
	}

}
